<template>
	<view class="intelligentInvestment">
		<topTitle :title="$t('intelligentInvestment.title')" />
		<view class="com">
			<view class="detail">
				<view>
					<image :src="obj.icon" mode="widthFix" />
				</view>
				<view>
					<view class="name">{{ obj.name }}</view>
					<view>{{ $t('intelligentInvestment.dailyRate') }}：<text>{{ obj.rate * 100 }}%</text></view>
					<view>{{ $t('intelligentInvestment.investmentCycle') }}：<text>{{ obj.cycle }}{{ $t('invest.day') }}</text></view>
					<view>{{ $t('intelligentInvestment.investmentPrice') }}：<text class="price">{{ obj.price }} USDT</text></view>
				</view>
			</view>

			<view class="balance">
				<view>{{ $t('intelligentInvestment.availableBalance') }}</view>
				<view>{{ UserMoneyInfo.balance_wisdom || 0 }}<text>USDT</text></view>
			</view>

			<view class="ipt">
				<view>
					<view>{{ $t('intelligentInvestment.purchaseLimit') }}</view>
					<view>{{ obj.price }}USDT</view>
				</view>
				<view>
					<view>{{ $t('intelligentInvestment.investmentQuantity') }}</view>
					<view>1</view>
				</view>
				<view>
					<view>{{ $t('intelligentInvestment.dailyReturn') }}</view>
					<view>{{ obj.rate * 100 }}%</view>
				</view>
				<view>
					<view>{{ $t('intelligentInvestment.investmentPeriod') }}</view>
					<view>{{ obj.cycle }}{{ $t('invest.day') }}</view>
				</view>
				<view>
					<view>{{ $t('intelligentInvestment.expectedIncome') }}</view>
					<view>{{ obj.price }} *1 *{{ obj.rate * 100 }}% * {{ obj.cycle }} = {{ obj.price * 1 * obj.rate *
						obj.cycle
					}}USDT</view>
				</view>
			</view>
		</view>

		<view class="fot">
			<view @click="investmentFn">{{ obj.price }}USDT {{ $t('intelligentInvestment.invest') }}</view>
		</view>
	</view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance } from "vue";
const instance = getCurrentInstance()?.appContext.config.globalProperties;

import { onLoad } from "@dcloudio/uni-app";
import { UserMoney } from "@/api/UserApi";

let obj = ref<any>({})
let UserMoneyInfo = ref<any>({})

onLoad((options: any) => {
	UserMoneyFn()
	if (options.obj) {
		obj.value = JSON.parse(options.obj)
	}
});

const UserMoneyFn = () => {
	UserMoney().then((e) => {
		UserMoneyInfo.value = e
	})
}

const investmentFn = () => {
	if (UserMoneyInfo.value?.balance_wisdom < obj.value.price) {
		uni.showToast({ title: instance?.$t('intelligentInvestment.insufficientBalance'), icon: 'none' })
		return
	}
	uni.showModal({
		content: instance?.$t('intelligentInvestment.confirmPurchase'),
		confirmText: instance?.$t('intelligentInvestment.confirm'),
		cancelText: instance?.$t('intelligentInvestment.cancel'),
		success: (res) => {
			if (res.confirm) {
				instance?.goRedirectTo('/pages/setUp/enterPsw?type=intelligentInvestment&title=' + instance?.$t('intelligentInvestment.investmentSuccess') + '&id=' + obj.value.Id)
			}
		}
	})
}
</script>

<style scoped lang="scss">
@import "../../static/scss/invest.scss";
</style>
